let pswrds = document.querySelectorAll('#pswrd');
let toggleBtns = document.querySelectorAll('#toggleBtn');
let lowerCase = document.getElementById('lower');
let upperCase = document.getElementById('upper');
let numberCase = document.getElementById('number');
let specialCase = document.getElementById('special');
let minLength = document.getElementById('length');
let reCheck = document.getElementById('recheck');
let pwd

//检查密码
function checkPassword(data) {
    pwd = data;

    //确定正则判断
    const lower = new RegExp('(?=.*[a-z])');
    const upper = new RegExp('(?=.*[A-Z])');
    const number = new RegExp('(?=.*[0-9])');
    const special = new RegExp('(?=.*[!@#\$%\^&\*])');
    const length = new RegExp('(?=.{8,})');

    //小写字母判断
    if (lower.test(data)) {
        lowerCase.classList.add('valid');
    } else {
        lowerCase.classList.remove('valid');
    };

    //大写字母判断 
    if (upper.test(data)) {
        upperCase.classList.add('valid');
    } else {
        upperCase.classList.remove('valid');
    };

    //数字判断
    if (number.test(data)) {
        numberCase.classList.add('valid');
    } else {
        numberCase.classList.remove('valid');
    };

    //特殊字符判断
    if (special.test(data)) {
        specialCase.classList.add('valid');
    } else {
        specialCase.classList.remove('valid');
    };

    //长度判断
    if (length.test(data)) {
        minLength.classList.add('valid');
    } else {
        minLength.classList.remove('valid');
    };

}

//检查确认密码
function recheckPassword(data) {
    if (data === '') {
        reCheck.classList.remove('valid');
    }
    else if (data === pwd) {
        reCheck.classList.add('valid');
    } else {
        reCheck.classList.remove('valid');
    };
};

//控制密码框输入和隐藏
for (let i = 0; i < toggleBtns.length; i++) {
    toggleBtns[i].onclick = function () {
        if (pswrds[i].type === 'password') {
            pswrds[i].setAttribute('type', 'text');
            toggleBtns[i].classList.add('hide');
        } else {
            pswrds[i].setAttribute('type', 'password');
            toggleBtns[i].classList.remove('hide');
        };
    };
};